﻿
using System;
using System.Data;
using System.Data.OleDb;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace Common
{
	/// <summary>
	/// Description of ComboxDataSourceUtil.
	/// </summary>
	public class ComboxDataSourceUtil
	{
        private ComboxDataSourceUtil()
		{
		}


        public static DataTable getSymptomKind()
        {
            string sql = "select distinct(s.kind) as name from Symptom s group by s.kind";
            DataSet ds = AccessDBUtil.ExecuteQuery(sql);
            return ds.Tables["ds"];
        }

        public static DataTable getSympComplexity(string kind)
        {
            string sql = "select distinct(s.complexity) as name from Symptom s where s.kind=? group by s.complexity";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@kind", OleDbType.VarChar);
            parameters[0].Value = kind;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql,parameters);
            return ds.Tables["ds"];
        }

        public static DataTable getSympPart(string kind,string complexity)
        {
            string sql = "select distinct(s.part) as name from Symptom s where s.kind=? and s.complexity=? group by s.part";
            OleDbParameter[] parameters = new OleDbParameter[2];
            parameters[0] = new OleDbParameter("@kind", OleDbType.VarChar);
            parameters[0].Value = kind;
            parameters[1] = new OleDbParameter("@complexity", OleDbType.VarChar);
            parameters[1].Value = complexity;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            return ds.Tables["ds"];
        }

        public static DataTable getSymptom(string kind, string complexity,string part)
        {
            string sql = "select id,state from  Symptom  where kind=? and complexity=? and part=?";
            OleDbParameter[] parameters = new OleDbParameter[3];
            parameters[0] = new OleDbParameter("@kind", OleDbType.VarChar);
            parameters[0].Value = kind;
            parameters[1] = new OleDbParameter("@complexity", OleDbType.VarChar);
            parameters[1].Value = complexity;
            parameters[2] = new OleDbParameter("@part", OleDbType.VarChar);
            parameters[2].Value = part;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            return ds.Tables["ds"];
        }

        public static DataTable getExamType()
        {
            string sql = "select distinct(e.type) as name from Examination e group by e.type";
            DataSet ds = AccessDBUtil.ExecuteQuery(sql);
            return ds.Tables["ds"];
        }

        public static DataTable getExamItem(string type)
        {
            string sql = "select id,item from Examination where type=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@type", OleDbType.VarChar);
            parameters[0].Value = type;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql,parameters);
            return ds.Tables["ds"];
        }

        public static DataTable getDrug()
        {
            string sql = "select id,name from Drug order by name asc";
            DataSet ds = AccessDBUtil.ExecuteQuery(sql);
            return ds.Tables["ds"];
        }

        public static DataTable getFollowDiagnoses(int patient_id)
        {
            string sql = "select id,create_date from DiagnoseMstr where patient_id=? and is_first=? order by create_date desc";
            OleDbParameter[] parameters = new OleDbParameter[2];
            parameters[0] = new OleDbParameter("@type", OleDbType.Integer);
            parameters[0].Value = patient_id;
            parameters[1] = new OleDbParameter("@type", OleDbType.Boolean);
            parameters[1].Value = false;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            return ds.Tables["ds"];
        }

        public static DataTable getFollowTCMs(int patient_id)
        {
            string sql = "select id,create_date from TCM where patient_id=? order by create_date desc";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@type", OleDbType.Integer);
            parameters[0].Value = patient_id;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            return ds.Tables["ds"];
        }
		
	}
}
